<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
 <%
 	String path = request.getContextPath();
 	request.setAttribute("path", path);
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="CoreUI - Open Source Bootstrap Admin Template">
    <meta name="author" content="Łukasz Holeczek">
    <meta name="keyword" content="Bootstrap,Admin,Template,Open,Source,AngularJS,Angular,Angular2,jQuery,CSS,HTML,RWD,Dashboard">
    <link rel="shortcut icon" href="${path}/img/favicon.png">

	<!-- tree -->
	<link rel="stylesheet" href="${path}/css/bootstrap.min.css" type="text/css"> 
	 <link rel="stylesheet" href="${path}/css/demo.css" type="text/css">
	<link rel="stylesheet" href="${path}/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="${path}/js/jquery.min.js"></script>
	<script type="text/javascript" src="${path}/js/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${path}/js/jquery.ztree.excheck.js"></script>
	  <script type="text/javascript" src="${path}/js/jquery.ztree.exedit.js"></script>
	 
	 	 
   <script type="text/javascript" src="${path}/js/bootstrap.min.js"></script>


    <!-- Icons -->
    <link href="${path}/css/font-awesome.min.css" rel="stylesheet">
    <link href="${path}/css/simple-line-icons.css" rel="stylesheet">

    <!-- Main styles for this application -->
    <link href="${path}/css/style.css" rel="stylesheet">
	

   <!-- ================================================== -->
    <!-- ================================================== -->
     <!-- ================================================== --> 
<%-- 	<script src="${path}/dist/jquery.table2excel.js"></script>
  --%>   <script type="text/javascript">
   		
    
    	var parentId=0;
    	var isGroup=0;
    	var id=0;
    	var pId=0;
	    <!--
			var setting = {

				data: {
					key: {
						title:"t"
					},
					simpleData: {
						enable: true,
						 
					}
				},
				 view: {  
				     selectedMulti:false  
				    },
				 /* check:{  
					   enable:true   //设置是否显示checkbox复选框  
					  }, */ 
				callback: {
					beforeClick: beforeClick,
					onClick: onClick,
				 	onRightClick: OnRightClick,  
					
				},
			};
	    
			var zNodes =[
				<c:forEach var="f" items="${functionauthorityList}">
				{id:${f.functionauthorityId},pId:${f.parentId},name:"${f.name}",t:${f.isgroup},open:true},
				</c:forEach> 
				
			];
			var log, className = "dark";
			function beforeClick(treeId, treeNode, clickFlag) {
				className = (className === "dark" ? "":"dark");
				showLog("[ "+getTime()+" beforeClick ]&nbsp;&nbsp;" + treeNode.name );
				return (treeNode.click != false);
			}
			function onClick(event, treeId, treeNode, clickFlag) {
				parentId=treeNode.id;
				hideRMenu();
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				showLog("[ "+getTime()+" onClick ]&nbsp;&nbsp;clickFlag = " + clickFlag + " (" + (clickFlag===1 ? "普通选中": (clickFlag===0 ? "<b>取消选中</b>" : "<b>追加选中</b>")) + ")");
				if(treeNode.t==1){
					
					window.location.href="${path}/auth/functionauthority/showParent?parentId="+treeNode.id;
				}
				
				
			}
			function OnRightClick(event, treeId, treeNode) {
				parentId=treeNode.id;
				isGroup=treeNode.t;
				pId=treeNode.pId;
				if(treeNode.t==1){
					showRMenu("fafa",event.clientX, event.clientY);//根据鼠标位置显示右键操作面板
				}else{
					showRMenu("root",event.clientX, event.clientY);//根据鼠标位置显示右键操作面板
				}
				
				
			} 
			function showRMenu(type,x, y) {  
				
				$("#rMenu ul").show();  
				
				 if(type == "root") {  
				  $("#m_del").show();  
				  $("#m_add").hide();  
				 }else {  
				  $("#m_del").show();  
				  $("#m_add").show();  
				 }  
				 $("#rMenu").css({"top": y + "px","left": x + "px","visibility": "visible","position": "absolute" });  
				 $("body").bind("mousedown", onBodyMouseDown);  
				}  
				//以藏右键面板  
				function hideRMenu() {  
					$("#rMenu").css({ "visibility":"hidden" });  
				 $("body").unbind("mousedown", onBodyMouseDown);  
				}  
				//单击页面其他位置 隐藏右键面板  
				function onBodyMouseDown(event) {  
				 if(!(event.target.id == "rMenu"|| $(event.target).parents("#rMenu").length > 0)) {  
					 $("#rMenu").css({"visibility": "hidden" });  
				 }  
				}  
			
				 
			function showLog(str) {
				if (!log) log = $("#log");
				log.append("<li class='"+className+"'>"+str+"</li>");
				if(log.children("li").length > 8) {
					log.get(0).removeChild(log.children("li")[0]);
				}
			}
			function getTime() {
				var now= new Date(),
				h=now.getHours(),
				m=now.getMinutes(),
				s=now.getSeconds();
				return (h+":"+m+":"+s);
			}
			function addTreeNode(){
				if($("#recipient-name").val()==""){
					alert("资源不能为空");
					return;
				}
				if($("#keyValue").val()==""){
					alert("keyvalue不能为空值");
					return;
				}
				var name=$("#recipient-name").val();
				var isgroup=$("input[type=radio]:checked").val();
				var keyValue=$("#keyValue").val();
				$.ajax({
					type:"POST",
					url:"${path}/auth/functionauthority/add",
					data:{
						name:name,
						parentId:parentId,
						isgroup:isgroup,
						keyValue:keyValue
					},
					success:function(data){
						if(data=="true"){
							alert("OK");
							window.location.href="${path}/auth/functionauthority/showParent?parentId="+parentId;
						}else if(data=="false"){
							alert("资源名称或者keyValue存在相同");
						}else{
							alert("你没有添加资源的权限");
						}
						
					},
					error:function(){
						alert("error");
					}
				})
			}
			function search(){
				$("#findName").submit();
			}
			
			$(document).ready(function(){
				var i=0;
				$("#recipient-name").blur(function(){
					if(i==3){
						
						return;
					}
					var addName=$(this).val();
					if(addName==""){
						i=6;
						return;
					}
					$.ajax({
						type:"POST",
						url:"${path}/auth/functionauthority/addCheckByName",
						data:{
							addName:addName,
							parentId:parentId,
						},
						success:function(data){
							if(data=="true"){
								alert("出现重复的资源名称，请重输入");
								i=1;
								$("button[name=save]").prop("disabled","true");
								return;
							}else{
								i=2;
								$("button[name=save]").prop("disabled","");
							}
						}, 
						error:function(){
							alert("error");
						}
					});
				});
		
				$("#keyValue").blur(function(){
					if(i==1){
						return;
					}
					var addkeyValue=$(this).val();
					if(addkeyValue==""){
						i=5;
						return;
					}
					$.ajax({
						type:"POST",
						url:"${path}/auth/functionauthority/addCheckByName",
						data:{
							addkeyValue:addkeyValue,
							parentId:parentId,
						},
						success:function(data){
							if(data=="true"){
								alert("出现重复的值的名字,请重新输入");
								i=3;
								$("button[name=save]").prop("disabled","true");
								return;
							}else{
								i=4;
								$("button[name=save]").prop("disabled","");
							}
						}, 
						error:function(){
							alert("error");
						}
					});
				});
				var input = $('#pageNum');
				$(".pagination li").click(function(){
		    		var v=this.value;
		    		if(v==0){
		    			return;
		    		}
		    		input.val(v);
		    		var $parentId=$("#parentId").val();
		    		if($parentId>0){
		    			window.location.href="${path}/auth/functionauthority/showParent?parentId="+$parentId+"&pageNum="+v;
		    		}else{
		    			$("#findName").submit();
		    		}
		    	});
				$.fn.zTree.init($("#treeDemo"), setting, zNodes);
				$("input[name=checkAll]").click(function(){
			    		if($(this).prop("checked")==true){
			                  $("input[name=checkSelect]").prop("checked","true");
			           		}else{
			                 $("input[name=checkSelect]").prop("checked","");
			             }
			              
			          });
					$("#cl").click(function(){
						$(".poster").slideToggle();
					});
			});
			function del(){
				var page=$("#pageNum").val();
				var parentId=parseInt($("#parentId").val());
				var delName=$("input[name=name]").val();
    			var checkedNum=$("input[name=checkSelect]:checked").length;
				if(checkedNum==0){
					alert("至少选择一项");
					return;
				}
				var checkedList=new Array();
				$("input[name=checkSelect]:checked").each(function(){
					checkedList.push($(this).val());
				});
				$.ajax({
					type:"get",
					url:"${path}/auth/functionauthority/del",
					data:"delitems="+checkedList.toString(),
					success:function(data){
						if(data=="true"){
							alert("OK");
							if(parentId>0){
								window.location.href="${path}/auth/functionauthority/list?parentId="+parentId+"&pageNum="+page;
				    		}else{
				    			$("#findName").submit();
				    		}
							$("#delSuccess").text("删除成功");
						}else if(data=="false"){
							$("#delSuccess").text("含有下一级，不能删除");
						}else{
							$("#delSuccess").text("你没有删除资源的权限");
						}
					}, 
					error:function(){
						alert("error");
					}
				});
    		}
			//-->
			
			
    </script>
    <style type="text/css">
    	
    	#functionauthorityContext{
    		margin-top:3px;
    		width:75%;
			float:left;
			
		}
		
	</style>
</head>
<body class="app header-fixed sidebar-fixed aside-menu-fixed aside-menu-hidden">

	<!-- 头部 -->
    <%@ include file="/share/header.jsp" %>

	<!-- 权限管理 -->
<div class="app-body">
	<%@ include file="/share/sidebar.jsp" %>
    <div class="main">
    <div class="row">
  
  
</div><!-- /.row -->

<div class="right">
		<div class="zTreeDemoBackground left" >
			<ul id="treeDemo" class="ztree"></ul>
			<div id="rMenu" style="visibility: hidden;">
				 <ul>
				   <li id="m_add">
				   <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">增加</button>

						<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
						  <div class="modal-dialog" role="document">
						    <div class="modal-content">
						      <div class="modal-header">
						       <h4 class="modal-title" id="exampleModalLabel">增加权限信息</h4>
						        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						       
						      </div>
						      <div class="modal-body">
						       <form id="userForm" action="${path}/auth/functionauthority/add" method="post">
						          <div class="form-group">
						            <label for="recipient-name" class="control-label">权限资源名称:</label>
						            <input type="text" class="form-control" id="recipient-name">
						          
						          </div>
						          		<div class="form-group">
							            <label for="message-text" class="control-label">是否允许继续分组:</label>
							             <input type="radio" value="1" checked="checked" name="haha" id="message-text"/>1(继续分组)
							              <input type="radio" value="2" name="haha" id="message-text"/>2(停止分组)
							         
         						 	</div>
         						 	<div class="form-group">
							            <label for="message-text" class="control-label">keyValue:</label>
							              <input type="text" class="form-control" id="keyValue">
							       </div>
						        </form>
						      </div>
						      <div class="modal-footer">
						        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						        <button type="button" class="btn btn-primary" name="save" onclick="addTreeNode();">保存</button>
						      </div>
						    </div>
						  </div>
				   </li>
				 </ul>
				 
			</div>
		</div>
		
	
		
	<div id="functionauthorityContext">
	<div id="fluid" class="container-fluid">
	<div class="animated fadeIn">
	<div class="row">
	<div class="col-lg-12">
	<div class="card">
		<div class="card-header">
			
			<div class="col-lg-6">
			   <form id="findName" action="${path}/auth/functionauthority/findByName" method="post">
			    <div class="input-group">
    
    	<label>输入资源名称：</label>
      <input type="text" name="name" class="form-control" placeholder="输入资源名称" value="${name}">
      <span class="input-group-btn">
       <input type="hidden" id="pageNum" name="pageNum" value="${pageNum}" />
       <input type="hidden" id="parentId" name="parentId" value="${parentId}" />
  	 	<input type="hidden" id="haha" name="haha" value="${pageNum}"/>
        <button class="btn btn-default" type="button" onclick="search();">查询</button>
      </span>
     
    </div><!-- /input-group -->
   
     </form>
  </div><!-- /.col-lg-6 -->
			
		</div>
	<div class="card-block">
		<table class="table table-bordered table-striped table-condensed">
		<thead>
		<tr>
			<th><input type="checkBox" name="checkAll"/>
				 <div class="btn-group" role="group" aria-label="...">
 				 <button type="button" class="btn btn-default" onclick="del();">删除</button>
 			</div>
			</th>
			<th>操作权限序号</th>
			<th>名称</th>
		</tr>
		</thead>
		<tbody id="row">
			<c:forEach var="function" items="${fByParent}" varStatus="status">
			<tr>
				<td><input type="checkbox" name="checkSelect" value="${function.functionauthorityId}"></td>
				<td>${status.index+1}</td>
				<td><c:out value="${function.name}"/></td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div id="delSuccess"></div>
	<div>${msg}</div>
	 <nav id="nav">
		<ul class="pagination">
			<li value="${queryByPage.prePage}" class="page-item">
				<a class="page-link" href="javascript:void(0)">上一页</a>
			</li>
			<c:forEach var="p" items="${queryByPage.navigatepageNums}" varStatus="status">
				<li value="${p}" class="page-item active">
					<a class="page-link" href="javascript:void(0)">${p}</a>
				</li>
			</c:forEach>

				<li value="${queryByPage.nextPage}" class="page-item">
					<a class="page-link" href="javascript:void(0)">下一页</a>
				</li>
			</ul>
		</nav>
	</div>
		</div>	
			</div>
			</div>
			</div>
			</div>
    		</div>
   		 </div>
	</div>
	</div>

<!-- </div> -->
</body>
</html>